#pragma once

#include "Widget.h" 
#include "CustomWindow.h"

namespace My {

class ScrollBox : 
	public CustomWindow<CWnd>,
	public EventDispatcher
{
public:
	class ScrollBar {
	public:
		ScrollBar(ScrollBox &);
	public:
		bool IsEnabled() const 
			{ return m_Enabled; }
		bool IsAlwaysVisible() const
			{ return m_AlwaysVisible; }
		void Enable(bool);
		void SetAlwaysVisible(bool);
	private:
		ScrollBox &	m_Owner;
		bool		m_Enabled;
		bool		m_AlwaysVisible;
	};
public:
	ScrollBox();
public:
	CPoint GetOffset() const
		{ return m_Offset; }
	void SetOffset(CPoint);
	ScrollBar & GetHorzBar()
		{ return m_Horz; }
	ScrollBar & GetVertBar()
		{ return m_Vert; }
	int GetAlignment() const
		{ return m_Alignment; }
	void SetAlignment(int);
	CSize GetPreferredContentSize() const
		{ return m_Preferred; }
	void SetPreferredContentSize(CSize);
	CSize GetContentSize() const;
public:
	virtual void UpdateBounds();
	virtual void HandleWindowCreate();
public:
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
	DECLARE_MESSAGE_MAP()
private:
	CSize GetMaxClientSize() const; // without scrollbars
	CSize CalcClientSize() const;
	void UpdateScrollBars();
private:
	CPoint			m_Offset;
	ScrollBar		m_Horz;
	ScrollBar		m_Vert;
	CSize			m_Preferred;
	int				m_Alignment;
	bool			m_SBUpdate;
};

class WidgetScrollBox : public ScrollBox {
public:
	WidgetScrollBox();
public:
	Widget * GetWidget() const
		{ return m_pWidget; }
	void SetWidget(Widget *);
public:
	virtual void HandlePaint(CDC *, const CRect &);
	virtual void LayoutControls();
private:
	Widget * m_pWidget;
};

} // My
